package com.changgou.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Service;

import java.io.Serializable;

/**
 * 响应结果
 * @author gaofeng
 * @date 2025/4/20 21:46
 */
@Setter
@Getter
@ApiModel(description = "Result", value = "Result")
public class Result<T> implements Serializable {
    /**
     * 是否成功
     */
    @ApiModelProperty(value = "执行是否成功", required = true)
    private boolean flag;

    /**
     * 返回码
     */
    @ApiModelProperty(value = "返回状态码", required = true)
    private Integer code;

    /**
     * 返回消息
     */
    @ApiModelProperty(value = "提示信息", required = true)
    private String message;

    /**
     * 返回数据
     */
    @ApiModelProperty(value = "逻辑数据", required = true)
    private T data;

    public Result(boolean flag, Integer code, String message, Object data) {
        this.flag = flag;
        this.code = code;
        this.message = message;
        this.data = (T) data;
    }

    public Result(boolean flag, Integer code, String message) {
        this.flag = flag;
        this.code = code;
        this.message = message;
    }

    public Result() {
        this.flag = true;
        this.code = StatusCode.OK;
        this.message = "操作成功!";
    }
}
